package com.war.dao.stock;
import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.warehousing.PurchaseInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DamagesDao {

    @Insert("INSERT INTO stock_damages(" +
            "id,product_name,damages_num,warehouse_name,operator_id,damage_datetime,damage_reason) VALUES(" +
            "UNIX_TIMESTAMP(NOW())+RAND()*10000,#{product_name},#{damages_num},#{warehouse_name}," +
            "'123'" +//用户id  后续从session中获取
            ",NOW(),#{damage_reason})")
    int add(DamagesInfo damagesInfo);



    @Delete("DELETE FROM stock_damages WHERE id=#{id}")
    int deleteById(DamagesInfo damagesInfo);

    //id,product_name,damages_num,warehouse_name,damage_reason
    @Update("UPDATE stock_damages SET " +
            "product_name=#{product_name}," +
            "damages_num=#{damages_num}," +
            "warehouse_name=#{warehouse_name}," +
            "damage_reason=#{damage_reason}" +
            " WHERE id=#{id}")
    int updateById(DamagesInfo damagesInfo);


    @Select("select stock_damages.id,product_name,damages_num,warehouse_name,operator_id,damage_datetime,damage_reason,sys_user.name as warehouse_manager\n" +
            "from stock_damages,sys_warehouse,sys_user\n" +
            "where sys_warehouse.name=stock_damages.warehouse_name and sys_user.id=sys_warehouse.manager\n" +
            "order by damage_datetime")
    List<DamagesInfo> selectAll();

    @Select("select stock_damages.id,product_name,damages_num,warehouse_name,operator_id,damage_datetime,damage_reason,sys_user.name as warehouse_manager\n" +
            "from stock_damages,sys_warehouse,sys_user\n" +
            "where sys_warehouse.name=stock_damages.warehouse_name and sys_user.id=sys_warehouse.manager and stock_damages.product_name=#{conValue}\n" +
            "order by damage_datetime")
    List<DamagesInfo> selectByProductName(DamagesInfo damagesInfo);

    @Select("select stock_damages.id,product_name,damages_num,warehouse_name,operator_id,damage_datetime,damage_reason,sys_user.name as warehouse_manager\n" +
            "from stock_damages,sys_warehouse,sys_user\n" +
            "where sys_warehouse.name=stock_damages.warehouse_name and sys_user.id=sys_warehouse.manager and stock_damages.warehouse_name=#{conValue}\n" +
            "order by damage_datetime")
    List<DamagesInfo> selectByWareHouseName(DamagesInfo damagesInfo);

    @Select("select * from stock_damages where id=#{id}")
    List<DamagesInfo> selectById(DamagesInfo damagesInfo);

    //报表
    @Select("SELECT product_name,damages_num FROM stock_damages")
    List<DamagesInfo> damages_num_data();

}
